package com.hgyc.mom.qms.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hgyc.mom.common.vo.Result;
import com.hgyc.mom.core.mybatis.QueryWrapperUtil;
import com.hgyc.mom.qms.entity.QmsIqcRecord;
import com.hgyc.mom.qms.service.QmsIqcRecordService;
import com.hgyc.mom.qms.vo.QmsIqcDetailVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 来料检验单缺陷记录Controller
 *
 * @author fwj
 * @since 2025-09-27
 */
@Tag(name = "来料检验单缺陷记录控制器", description = "来料检验单缺陷记录控制器")
@RestController
@RequestMapping("/qms/iqc/record")
public class QmsIqcRecordController {
    @Autowired
    private QmsIqcRecordService qmsIqcRecordService;


    @Operation(summary = "查询来料检验单缺陷记录树列表", description = "查询来料检验单缺陷记录树列表")
    @PostMapping("/list")
    public Result<List<QmsIqcRecord>> pageList(@Parameter(description = "查询参数") @RequestBody QmsIqcRecord qmsIqcRecord) {
        QueryWrapper<QmsIqcRecord> wrapper = QueryWrapperUtil.build(qmsIqcRecord);
        List<QmsIqcRecord> list = qmsIqcRecordService.list(wrapper);
        return Result.success(list);
    }

    @Operation(summary = "获取来料检验单缺陷记录详细信息", description = "获取来料检验单缺陷记录详细信息")
    @GetMapping(value = "/{id}")
    public Result<QmsIqcRecord> getInfo(@Parameter(description = "来料检验单缺陷记录ID") @PathVariable("id") Long id) {
        return Result.success(qmsIqcRecordService.getById(id));
    }

    @Operation(summary = "批量保存不良记录", description = "批量保存不良记录")
    @PostMapping("/batchSave")
    public Result<?> batchSave(@RequestBody QmsIqcDetailVO qmsIqcDetailVO) {
        qmsIqcRecordService.saveRrecord(qmsIqcDetailVO);
        return Result.success();
    }

    @Operation(summary = "删除不良记录", description = "删除不良记录")
    @DeleteMapping
    public Result<?> deleteBatch(@Parameter(description = "删除ID") @RequestParam("ids") Long[] ids) {
        qmsIqcRecordService.removeByIds(Arrays.asList(ids));
        return Result.success();
    }
}
